 <{capture name="header"}>
<link href="../apps/ome/statics/ome.css" rel="stylesheet"
    type="text/css">
<{/capture}>

<div class="tableform">
    <h3>
        工作人员添加
    </h3>
    <div class="division">
        <form method="post" id="fm1"
            action="index.php?app=omekpi&ctl=admin_employee&act=doadd">

            <{button id="user-find-btn" type="button" class="btn" label="选择人员" }>
            类型:
            <select name="select" id="select">
                <option value='servicer'>
                    客服员工
                </option>
                <option value='packager'>
                    打包员工
                </option>
                <option value='pickinger'>
                    配货员工
                </option>
                <option value='deliverier'>
                    发货员工
                </option>
            </select>
            <table>
                <thread>
                <tr>
                    <td></td>
                    <td>
                        员工编号
                    </td>
                    <td>
                        员工帐号
                    </td>
                    <td>
                        员工姓名
                    </td>
                </tr>
                </thread>
                <tbody id="dataNode">
                    <tr>
                        <td colspan="7" style="padding: 0;">
                            <div class="note" style="margin: 0;">
                                暂无需加客服人员信息
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div align="right">
                <{button type="button" id="purchase-delall-btn" label="全部删除" }>
            </div>
            <div id="cc" class="noprint table-action">
                <{button type="button" class="btn" id="purchase-save-btn" label="保
                存"}> &nbsp; <{button type="button" class="btn" id="return-btn"
                label="返 回" onclick="javascript:void(history.go(-1));"}>
            </div>
        </form>

    </div>

    <script>


(function(){
    var callurl='index.php?app=omekpi&ctl=admin_employee&act=getUserId',store=[];
    $('user-find-btn').addEvent('click',function(e){
        var url='index.php?app=desktop&act=alertpages&goto='+encodeURIComponent('index.php?app=omekpi&ctl=admin_employee&act=add');
        new finderDialog(url,{params:{url:callurl,name:'user_id[]'},width:1000,height:650,
            onCallback:function(rs){
            console.info(rs);
                if(!rs) return;
                rs=JSON.decode(rs);
                init(rs);
        }});
    });



    function init(rs){
        var tmparr=findUser(rs,'account_id');
         store.unshift.apply(store,tmparr.reverse());
          //alert(tmparr);
         createProduct(store);
         //alert(tmparr);
        //
    }
    function findUser(arr,PRIMARY){
        if(!store.length)return arr;
        store.each(function(a){
            arr.each(function(b){
                if(a[PRIMARY]==b[PRIMARY])arr.erase(b);
            });
        });
        return arr;
    }



    function emptyData(){
        var noData='<tr>'
            +'<td colspan="7" style="padding:0;"><div class="note" style="margin:0;"> 暂无客服人员信息 </div></td>'
            +'</tr>';
        $('dataNode').set('html',noData);
    }
    var tpl='<tr key="{account_id}" id="account_{account_id}" title="点击选取/反选此条记录">'
        +'  <td><input value="{account_id}" key="account_id" vtype="number&amp;&amp;required" tname="ut[]" size="6" disabled style="display:none"></td>'
        +'  <td><input value="{op_no}" key="op_no" vtype="" tname="ot[]" size="10" disabled></td>'
        +'  <td><input type="text" value="{login_name}" key="login_name" vtype="required" tname="at[]" size="10" disabled ></td>'
        +'  <td><input type="text" vtype="required"  tname="nr[]" key="name" value="{name}" size="10" disabled></td>'
        +'  <td><{img src="bundle/delecate.gif" app="desktop" key="state" class="pointer btn-delete-item"}></td>'
        +'</tr>';

    function createProduct(data){
        pag=new PageData(tpl,data,{'updateMain':$('dataNode'),'pageNum':10,PRIMARY_ID:'account_id',
        'onShow':function(){
             var _this=this;
             $$('#dataNode input[type]').addEvent('change',function(e){
                 var pid=this.getParent('tr').get('key'),value=this.value;
                 /*if(this.get('type')=='checkbox'){
                    if(!this.checked)$('purchase-delall-btn').checked=false;
                     value=this.checked?'checked':'';
                 }*/
                _this.editData(pid,[this.get('key'),value]);
            });
            /*var state=this.curdata.every(function(d){return d['state']=='checked';});
            $('purchase-delall-btn').checked=!state?false:true;
            attachEsayCheck($('dataNode'),'input[type=checkbox]');*/
            rows=$ES('#dataNode tr');

            rows.each(function(item,i){
                item.addEvent('click',function(e){
                    this.toggleClass('selected');
                });
                item.getElement('.btn-delete-item').addEvent('click',function(e){
                    if(_this.selectData(item.get('key')) && confirm('确定要删除 '+ _this.selectData(item.get('key'))['name'] +' 吗？')) _this.delData(item.get('key'));
                    if(!$E('#dataNode tr')) emptyData();
                });

                item.getElement('input[tname^=at]').addEvent('keypress',function(e){
                    if(e.code==13) $E('#pfba input').focus();
                });

            });
            //var len = this.data.length ? (this.data.length > this.options.pageNum ? (this.options.current == this.getTotal() ? this.data.length-this.options.pageNum*(this.options.current-1) : this.options.pageNum) : this.data.length) : 0;
            if(this.data.length) rows[0].getElement('input[key^=login_name]').focus();
        }
        });
    }

    $('purchase-save-btn').addEvent('click',function(e){
        //$('fm1').fireEvent('submit',{stop:function(){}});
        var form=this.getParent('form');
        if(pag){
            var data=pag.toHideInput($('dataNode').getElement('tr'));
             form.store('target',{extraData:data,
              onRequest:function(){
                 $('purchase-save-btn').set('disabled','true');
              },
              onComplete:function(jsontext){
                  try{
                      var json = Json.evaluate(jsontext);
                      if (typeof(json.error)!='undefined'){
                          $('purchase-save-btn').set('disabled','');
                      }else{
                          $('purchase-save-btn').set('disabled','true');
                      }
                  }catch(e){}
              }});
        }
        form.fireEvent('submit',e);
    });


    $('purchase-delall-btn').addEvent('click',function(e){
        //
        if(!pag||!pag.data) return;

        var delarr=[];
        pag.data.each(function(d){
             delarr.push(d['account_id']);
        });
        if(confirm('确认删除全部已选人员吗？')){
            delUser(pag,delarr);
            emptyData();
        }
    });


    function delUser(obj,arr){
        arr.each(function(d){obj.delData(d);});
    }




 /*    var callurl="index.php?app=omekpi&ctl=admin_deliverier&act=getOrders",store=[];
        $('order-find-btn').addEvent('click',function(e){
        var url="index.php?app=desktop&act=alertpages&goto='+encodeURIComponent("index.php?app=omekpi&ctl=admin_deliverier&act=getOrders" );
        new finderDialog(url,{params:{url:callurl,name:'order_id[]'},width:1000,height:650,
            onCallback:function(rs){
        }});
       });*/
})();

</script>